var navIndex = 0;

var layer = null;
var layerForm = null;

// 使用layui组件
layui.use(['laydate', 'layer', 'form'], function(){
  var laydate = layui.laydate;
  layer = layui.layer;
  
  //执行一个laydate实例
  laydate.render({
    elem: '#startInput' //指定元素
  });
  laydate.render({
    elem: '#endInput' //指定元素
  });
  layerForm = layui.form;
});

var app = new Vue({
  el: '#app',
  data: {
    tableDatas: TmpTableDatas[0]
  },
  created: function () {
    this.$nextTick(function () {
      // 渲染form表单
      layerForm.render();
    })
  }
})

// ztree配置
var zSetting = {
  data: {
    simpleData: {
      enable: true
    }
  }
};
    
$(document).ready(function(){
  // 初始化ztree控件
  $.fn.zTree.init($("#treeElm"), zSetting, zNodes);
});

//导航点击事件
$('.nav-list li.li-hook').on('click', function () {
  if (this.classList.contains('navActive')) return;
  $('.nav-list li.li-hook').removeClass('navActive');
  $(this).addClass('navActive');

  // 更改表格数据
  navIndex = (this.id).substring(3);
  app.tableDatas = TmpTableDatas[navIndex]
});

// 完成维修按钮点击事件
function showFin () {
  layer.open({
    type: 2,
    title: '完成维修',
    btnAlign: 'r',
    closeBtn: 2,
    area: ['810px', '400px'],
    shadeClose: true,
    skin: 'zcffModal', 
    content: './finRepair.html',
    btn: ['取消', '确定'],
    btn1: function (index, layero) {
      layer.close(index)
    },
    btn2: function (index, layero) {
      layer.close(index)
    }
  });
}

// 详情点击事件
function showDetail () {
  location.href = './amDetail.html?navIndex=' + navIndex
}
// 显示日志
function showLog () {
  layer.open({
    type: 2,
    title: '资产日志',
    btnAlign: 'c',
    closeBtn: 2,
    area: ['63%', '66%'],
    shadeClose: true,
    content: './assetsLog.html'
  });
}

// 资产入库点击事件
$('.am-zcrk-btn').on('click', function () {
  layer.open({
    type: 2,
    title: '资产入库',
    btn: ['确定'],
    btnAlign: 'c',
    closeBtn: 2,
    area: ['63%', '64%'],
    skin: 'zcrkModal', 
    shadeClose: true,
    content: './assetStorage.html',
    btn1: function (index, layero) {
      layer.close(index)
    }
  });
});

// 操作点击事件
$('.details-list li').on('click', function () {
  var id = this.id;
  switch (id) {
    case 'action0' :
      // 发放
      layer.open({
        type: 2,
        title: '发放',
        btnAlign: 'r',
        closeBtn: 2,
        area: ['820px', '640px'],
        shadeClose: true,
        skin: 'zcffModal', 
        content: './assetDistribution.html',
        btn: ['取消', '确定'],
        btn1: function (index, layero) {
          layer.close(index)
        },
        btn2: function (index, layero) {
          layer.close(index)
          // 打开资产入库页面填表
          layer.open({
            type: 2,
            title: false,
            btn: ['下一步'],
            btnAlign: 'c',
            closeBtn: 2,
            area: ['63%', '64%'],
            skin: 'zcrkModal', 
            shadeClose: true,
            content: './assetStorage.html',
            btn1: function (index, layero) {
              layer.close(index);
              // 打开资产分发下一步弹窗
              layer.open({
                type: 2,
                title: false,
                btn: ['取消', '确定', '预览'],
                btnAlign: 'c',
                closeBtn: 0,
                area: ['63%', '64%'],
                skin: 'zcffNextModal', 
                shadeClose: true,
                content: './assetDisNext.html'
              });
            }
          });
        }
      });
      break;
    case 'action1' :
      // 变更
      location.href = "./amUpdate.html"
      break;
    case 'action2' :
      // 回收
      layer.confirm(
        '回收操作会使资产将成为无使用人状态，是否仍要进行此项操作？', 
        { 
          title: '回收',
          btn: ['取消','确定'], //按钮
          closeBtn: 2,
          skin: 'hsModal',
          area: ['500px', '200px']
        }, 
        function(index, layero){
          layer.close(index)
        }, 
        function(index, layero){
          layer.close(index)
        }
      );
      
      break;
    case 'action3' :
      layer.open({
        type: 2,
        title: '调剂',
        btnAlign: 'r',
        closeBtn: 2,
        area: ['820px', '640px'],
        shadeClose: true,
        skin: 'zcffModal', 
        content: './assetDistribution.html',
        btn: ['取消', '确定'],
        btn1: function (index, layero) {
          layer.close(index)
        },
        btn2: function (index, layero) {
          layer.close(index)
          // 打开资产入库页面填表
          layer.open({
            type: 2,
            title: false,
            btn: ['下一步'],
            btnAlign: 'c',
            closeBtn: 2,
            area: ['63%', '64%'],
            skin: 'zcrkModal', 
            shadeClose: true,
            content: './assetStorage.html',
            btn1: function (index, layero) {
              layer.close(index);
              // 打开资产分发下一步弹窗
              layer.open({
                type: 2,
                title: false,
                btn: ['取消', '确定', '预览'],
                btnAlign: 'c',
                closeBtn: 0,
                area: ['63%', '64%'],
                skin: 'zcffNextModal', 
                shadeClose: true,
                content: './assetDisNext.html'
              });
            }
          });
        }
      });
      break;
    case 'action4' :
      // 维修
      layer.open({
        type: 2,
        title: '维修',
        btnAlign: 'r',
        closeBtn: 2,
        area: ['810px', '400px'],
        shadeClose: true,
        skin: 'zcffModal', 
        content: './repair.html',
        btn: ['取消', '确定'],
        btn1: function (index, layero) {
          layer.close(index)
        },
        btn2: function (index, layero) {
          layer.close(index)
        }
      });
      break;
    case 'action5' :
      // 报废
      layer.confirm(
        '报废操作后，资产将成为不可操作状态，是否仍要进行此项操作？', 
        { 
          title: '报废',
          btn: ['取消','确定'], //按钮
          closeBtn: 2,
          skin: 'hsModal',
          area: ['500px', '200px']
        }, 
        function(index, layero){
          layer.close(index)
        }, 
        function(index, layero){
          layer.close(index)
        }
      );
      break;
    case 'action6' :
      // 资产日志
      layer.open({
        type: 2,
        title: '资产日志',
        btnAlign: 'c',
        closeBtn: 2,
        area: ['63%', '66%'],
        shadeClose: true,
        content: './assetsLog.html'
      });
      break;
  }
})